<?php 
include('./fun.php');
$conn=my_sql($cfg);
$re=adm_login();
if($re['err']=='ok'){
 $adm=$re['adm']; 
}else{
$re=user_login();//用户登录
if($re['err']!='ok'){no_login();}
$user=$re['user'];
}


$sql='select * from '.$cfg['e'].'users ';
$state=g('state');
if($state!='stop'){$ss=1;}else{$ss=99;}
$sql.=' where state="'.$ss.'" ';

$key=g('key');
if($key){
$sql.=' and wx_nickname like "%'.a($key).'%" ';
}

$page=g('page');if(!$page){$page=1;}
$page_num=20;
$start=($page-1)*$page_num;
$sql.=' order by id desc limit '.$start.','.$page_num;
$l=db($sql);

?>
<style></style>
<hh><b>用户列表</b></hh>
<mm>
<index>
<?php $url=url_get(['page','state']);
echo '<a class="m " href="?'.$url.'">全部</a>';
echo '<a class="m '.($state=='stop'?'select':'').'" href="?'.$url.'&state=stop">禁用</a>';
?>

<input placeholder="请输入关键词" value="<?php echo $key?>"><a class="m" onclick="search_it($(this))">搜索</a>
</index>


<?php 
if($l){
echo '<table>';    
th(['logo','昵称','最近登录','地址','电话','邀请人','管理员','雇员','状态','操作']);
foreach($l as $v){
echo '<tr>';
echo '<td style="width:50px"><img src="'.$v['logo'].'" style="width:40px;height:40px;border-radius:50%;"></td>';

echo '<td>'.base64($v['nickname']).'</td>';

echo '<td style="font-size:12px">'.date('Y-m-d H:i',$v['last_login']).'</td>';
echo '<td>'.$v['city'].$v['addr'].'</td>';
echo '<td>'.$v['phone'].'</td>';
if($v['from_id']){
$u=get_user($v['from_id']);
$x=$u['nickname'];
}else{
$x='-';
}
echo '<td>'.$x.'</td>';

if($v['shop_id'] and $v['shop_state']){
$x='是';
}else{$x='否';}
echo '<td>'.$x.'</td>';

if($v['is_emp'] and $v['emp_state']){
$x='是';
}else{$x='否';}
echo '<td>'.$x.'</td>';

if($v['state']==1){
$x='正常';
}else{$x='禁用';}
echo '<td>'.$x.'</td>';

echo '<td>
'.($v['state']==1?'<a onclick="state($(this))" i="'.$v['id'].'" val="99">拉黑</a>':'<a onclick="state($(this))" i="'.$v['id'].'" val="1">恢复</a>').'

</td>';
echo '</tr>';
}
echo '</table>';
page();
}else{no_data();}

?>
</mm>




<script>
function state(o){
var id=o.attr('i');
var val=o.attr('val');
if(val!=1){val=99;}
var data={state:val}
if(val==99){
    if(!confirm("是否禁用该用户?")){return;}
}
post('adm_user_change',data,id,function(res){
    msg('修改成功');
    main_load();
});

}

function search_it(o){
var val=o.parent().find('input').val();
if(!val){val='';}
<?php 
$url=url_get(['page','key','state']);
?>
location.href="?<?php echo $url?>&key="+val;
    
}

</script>